#!/usr/bin/env python
#
'''
Created on 2009-3-25

@author: Wang_Yuan
'''

import random
import wx
from ExamSettingPanel_xrc import *
import ExamCommon

class ExamSettingPanel(xrcExamSettingPanel):
    '''
    Exam Setting Panel
    '''


    def __init__(self, parent, vocabulary):
        '''
        Constructor
        '''
        xrcExamSettingPanel.__init__(self, parent)
        maxQAmount = len(vocabulary.data)
        self.examWordList = vocabulary.getExamWordList()
        defaultQAmount = len(self.examWordList)
        self.questionAmount.SetRange(1, maxQAmount)
        self.questionAmount.SetValue(defaultQAmount)
        self.maxLabel.SetLabel('(max: %s)' % (maxQAmount))
        
    def getSettings(self):
        settings = ExamCommon.ExamSettings()
        if self.meanings2wordType.IsChecked():
            settings.addQType(ExamCommon.ExamSettings.Q_TYPE_MEANINGS2WORD)
        if self.example2wordType.IsChecked():
            settings.addQType(ExamCommon.ExamSettings.Q_TYPE_EXAMPLE2WORD)
        if self.word2meaningsType.IsChecked():
            settings.addQType(ExamCommon.ExamSettings.Q_TYPE_WORD2MEANINGS)
            
        settings.qAmount = self.questionAmount.GetValue()
        
        return settings
    
    def getExamWordList(self):
        return self.examWordList
    

def getExamSettingPanelBuilder(vocabulary):
    def getExamSettingPanel(parent):
        return ExamSettingPanel(parent, vocabulary)
    
    return getExamSettingPanel

